﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mortgage.Srv
{
    public static class CalculateHelper
    {
        public static int CalculateScale(DateTime start, DateTime end, Cls.EnmBillCalculateType type)
        {
            int result = 0;
            DateTime countStart = start;
            int dayAdd = 1;
            if (type == Cls.EnmBillCalculateType.Week)
                dayAdd = 7;
            do
            {
                result++;
                countStart = countStart.AddDays(dayAdd);

            } while (countStart < end);
            return result;
        }

        public static string BuildCalculateFomula(DateTime start, DateTime end, Cls.EnmBillCalculateType type, decimal interRate, out decimal caltotal)
        {
            string result;
            int num = CalculateScale(start, end, type) ;
            decimal total;
            int numDay = 4;
            if ( type == Cls.EnmBillCalculateType.Day)
                numDay = 30;
            else
                numDay = 4;

            total = num * ( interRate / numDay) ;
            result = string.Format("{0} x ( {1} / {2} ) = {3:0,0 VND}", num, interRate, numDay, total);
            caltotal = total;
            return result;
        }
    }
}
